package com.heima.admin.job;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.feigns.WemediaFeign;
import com.heima.model.common.dtos.ResponseResult;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Slf4j
public class WeMediaNewsAutoScanJob {
    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;
    @Autowired
    private WemediaFeign wemediaFeign;
    /**
     * 定时扫描待发布文章
     * @param param 任务参数
     * @return 定时任务结果
     * @throws Exception
     */
    @XxlJob("wemediaAutoScanJob")
    public ReturnT<String> autoScanJob(String param) throws Exception {
        log.info("自媒体文章审核调度任务开始执行....");
        ResponseResult<List<Integer>> release = wemediaFeign.findRelease();
        if(release.getCode().intValue()!=0){
            log.error("定时调度任务执行失败 ===================> "+release.getErrorMessage());
            return ReturnT.FAIL;
        }
        List<Integer> releaseIdList = release.getData();
        if(null!=releaseIdList && !releaseIdList.isEmpty()){
            for (Integer id : releaseIdList) {
                wemediaNewsAutoScanService.autoScanByMediaNewsId(id);
            }
        }
        log.info("自媒体文章审核调度任务执行结束....");
        return ReturnT.SUCCESS;
    }
}
